<?php
// $Id: dropdownlist.php 2014 2009-01-08 19:01:29Z dualface $

/**
 * 定义 Control_DropdownList 类
 *
 * @link http:om/
 * @copyright Copyright (c) 2006-2009 Qeeyuan Inc. {@link http://www.qeeyuan.com}
 * @license New BSD License {@link http://qeephp.c/}
 * @version $Id: dropdownlist.php 2014 2009-01-08 19:01:29Z dualface $
 * @package webcontrols
 */

/*ol_DropdownList 构造一个下拉列表框
 *
 * @author YuLei Liao <liaoyulei@qeeyuan.com>
 * @version $Id: dropdownlist.php 2014 2009-01-08 19:01:29Z dualface $
 * @package webcontrols
 */
class Control_Combobox extends QUI_Control_Abstract
{
    function render()
    {
        $value = $this->_extract('value');
        $items = $this->_extract('items');
        $non_htmlspecialchars = $this->_extract('non_htmlspecialchars');
        $emptyText = $this->_extract('emptyText');
        $emptyVal = $this->_extract('emptyVal');

        $out = '<div id="' . $this->id() . '_wrapper">';
        $out .= Q::control('dropdownlist', $this->id() . '_list', array(
                                                                       'items' => $items,
                                                                       'value' => $value,
                                                                       'emptyText' => $emptyText,
                                                                       'emptyVal' => $emptyVal,
                                                                       'non_htmlspecialchars' => $non_htmlspecialchars,
                                                                  ));

        $out .= Q::control('textbox', $this->id(), array('value' => $value));
        $out .= '</div>';
        $out .= '
<script type="text/javascript">
    $(function(){

        var $' . $this->id() . '_list = $("#' . $this->id() . '_list");
        var $' . $this->id() . '_wrapper = $("#' . $this->id() . '_wrapper");
        var $' . $this->id() . ' = $("#' . $this->id() . '");

        var ' . $this->id() . 'ListWidth = $' . $this->id() . '_list.outerWidth();
        $' . $this->id() . '_wrapper.css("width", ' . $this->id() . 'ListWidth + 12);

        if($.browser.msie || $.browser.mozilla){
            $' . $this->id() . '.width(' . $this->id() . 'ListWidth-17).css("margin-left", "-"+(' . $this->id() . 'ListWidth+5));
        }else{
            $' . $this->id() . '.width(' . $this->id() . 'ListWidth-17).css("margin-left", "-"+(' . $this->id() . 'ListWidth+10));
        }

        $' . $this->id() . '_list.change(function(){
            $' . $this->id() . '.val($.trim($("option:selected", $' . $this->id() . '_list).html()));
        });

        $' . $this->id() . '.change(function(){
            $' . $this->id() . '_list.val("");
        });
    });
</script>
';
        return $out;
    }
}

